package com.yk.faceapplication.activity;

import android.os.Bundle;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.allinpay.xed.R;
import com.android.volley.VolleyError;
import com.yk.faceapplication.callback.RequestCallback;
import com.yk.faceapplication.entity.Bill;
import com.yk.faceapplication.http.RequestUrl;
import com.yk.faceapplication.util.ImageUtil;
import com.yk.faceapplication.util.RequestUtil;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yk_2018/1/17_17:55
 */

public class AccountSettingActivity extends BaseActivity {
    private Bill account;

    private ImageView iconIV;
    private TextView nameTV;
    private TextView userNameTV;
    private TextView amountTV;
    private TextView accountNameTV;
    private Button commitBtn;

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        super.onClick(v);
        if (v.getId() == R.id.commit_btn) {
            updateAccountStatus();
        }
    }

    private void updateAccountStatus() {
        Map<String, String> form = new HashMap<String, String>();
//        form.put("accountId",account.getAccountId());
        RequestCallback callback = new RequestCallback() {
            @Override
            public void success(JSONObject jsonObject) {
                Toast.makeText(mApplication, "修改成功", Toast.LENGTH_SHORT).show();
                setResult(RESULT_OK);
                finishAct();
            }

            @Override
            public void fail(VolleyError volleyError) {

            }
        };
        RequestUtil.request(this, RequestUrl.UPDATE_BILL_STATUS+"token="+mToken+"&accountId="+account.getAccountId(), callback, form);
    }

    @Override
    protected void setTitle(String title) {
        // TODO Auto-generated method stub
        super.setTitle(title);
    }

    @Override
    protected void setTitleById(int id) {
        // TODO Auto-generated method stub
        super.setTitleById(id);
    }

    @Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        account = (Bill) getIntent().getSerializableExtra("account");
        iconIV = (ImageView) findViewById(R.id.prd_icon_img);
        nameTV = (TextView) findViewById(R.id.prd_name_tv);
        userNameTV = (TextView) findViewById(R.id.user_name_tv);
        amountTV = (TextView) findViewById(R.id.amount_tv);
        accountNameTV = (TextView) findViewById(R.id.account_name_tv);
        commitBtn = (Button) findViewById(R.id.commit_btn);
        if(account.getProductIconId() == null || account.getProductIconId().equals("")){
            iconIV.setImageResource(R.drawable.u62);
        }else{
            ImageUtil.displayImage(this, account.getProductIconId(), iconIV);
        }
        nameTV.setText(account.getLoanProductName());
        userNameTV.setText(account.getRealName()==null?"":account.getRealName());
        amountTV.setText(account.getLoanAmt());
        accountNameTV.setText(account.getAccountName());
        commitBtn.setText("设为已还");
        commitBtn.setOnClickListener(this);
        findViewById(R.id.topbar).setBackgroundDrawable(null);
    }

    @Override
    protected void initTransitionAnim() {
        // TODO Auto-generated method stub
        super.initTransitionAnim();
    }

    @Override
    protected void finishAct() {
        // TODO Auto-generated method stub
        super.finishAct();
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
    }

    @Override
    protected void onHandleMessage(Message msg) {
        // TODO Auto-generated method stub
        super.onHandleMessage(msg);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        return super.onKeyDown(keyCode, event);
    }

}
